package example

import (
	"embed"
	"github.com/gin-gonic/gin"
	"html/template"
	"net/http"
)

//go:embed html/*
var htmlFS embed.FS

//go:embed asset/*
var assetFS embed.FS

func main() {
	app := gin.Default()
	//引入js css  例如jquery.js  访问地址为 localhost:8080/asset/jquery.js
	app.Any("/asset/*filepath", func(c *gin.Context) {
		staticServer := http.FileServer(http.FS(assetFS))
		staticServer.ServeHTTP(c.Writer, c.Request)
	})
	// 引入html
	app.SetHTMLTemplate(template.Must(template.New("").ParseFS(htmlFS, "html/*")))

	app.Handle("GET", "/", index)

	app.Run()
}

func index(c *gin.Context) {
	c.HTML(http.StatusOK, "index.html", nil)
}
